package com.gs.zsmanage.config.shiroconfig;


import com.gs.zsmanage.utils.ShiroSession;
import com.gs.zsmanage.utils.WebUtil;
import org.apache.shiro.web.filter.PathMatchingFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//自定义拦截器,Session过期AJAX处理
public class SessionExpiredFilter extends PathMatchingFilter {

    @Override
    protected boolean onPreHandle(ServletRequest servletRequest, ServletResponse servletResponse, Object mappedValue) throws Exception {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String user = (String) ShiroSession.get("user_info");
        if (user == null) {
            if (WebUtil.isAjax(request)) {
                response.sendRedirect(request.getContextPath()+"/zs/login");
            } else {
                response.sendRedirect(request.getContextPath()+"/zs/login");
            }
            return false;
        }
        return true;
    }

}